package dxlateplate;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.users.User;

import java.util.Date;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable
public class LatePlate {
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;

    @Persistent
    private String name;
    
    @Persistent
    private String userName;
    
    @Persistent
    private String day;
    
    @Persistent
    private int type;
    
    @Persistent
    private String comments;
    
    @Persistent
    private int rHour = 0;
    
    @Persistent
    private int rMinute = 0;
    
    @Persistent
    private String rDay = "";
    
    @Persistent
    private String ampm = "";
    
    @Persistent
    private int value;
    
    @Persistent
    private boolean permanent;
    
    public LatePlate(String userName, String name, String day, int type, String comments, int rHour, int rMinute, int rDay, boolean permanent) {
    	this.userName = userName;
    	this.name = name;
    	this.day = day;
    	this.type = type;
    	this.comments = comments;
    	this.permanent = permanent;
    	
    	//Set correct hour
    	if (rHour == 0) {
    		setrHour(12);
    		setAmpm("AM");
    	} else if (rHour > 0 && rHour < 12) {
    		setrHour(rHour);
    		setAmpm("AM");
    	} else if (rHour == 12) {
    		setrHour(rHour);
    		setAmpm("PM");
    	} else if (rHour > 12) {
    		setrHour(rHour - 12);
    		setAmpm("PM");
    	}
    	
    	//set minute
    	this.rMinute = rMinute;
    	
    	//Set req day
    	if(rDay == 1) {
    		this.rDay = "Monday";
    	}
    	if(rDay == 2) {
    		this.rDay = "Tuesday";
    	}
    	if(rDay == 3) {
    		this.rDay = "Wednesday";
    	}
    	if(rDay == 4) {
    		this.rDay = "Thursday";
    	}
    	if(rDay == 5) {
    		this.rDay = "Friday";
    	}
    	
    	
    	//Set value based on day
    	if(day.equalsIgnoreCase("Monday")) {
    		this.value = 1;
    	}
    	if(day.equalsIgnoreCase("Tuesday")) {
    		this.value = 2;
    	}
    	if(day.equalsIgnoreCase("Wednesday")) {
    		this.value = 3;
    	}
    	if(day.equalsIgnoreCase("Thursday")) {
    		this.value = 4;
    	}
    	if(day.equalsIgnoreCase("Friday")) {
    		this.value = 5;
    	}
    }
    
    public String getReqTime() {
    	String colon = ":";
    	if (getrMinute() < 10) {
    		colon = ":0";
    	}
    	return getrDay() + " " + getrHour() + colon + getrMinute() + " " + getAmpm();
    }

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDay() {
		return day;
	}

	public void setDay(String day) {
		this.day = day;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public String getComments() {
		return comments;
	}

	public void setComments(String comments) {
		this.comments = comments;
	}

	public Key getKey() {
		return key;
	}
	
	public int getValue() {
		return value;
	}

	public int getrHour() {
		return rHour;
	}

	public void setrHour(int rHour) {
		this.rHour = rHour;
	}

	public int getrMinute() {
		return rMinute;
	}

	public void setrMinute(int rMinute) {
		this.rMinute = rMinute;
	}

	public String getrDay() {
		return rDay;
	}

	public void setrDay(String rDay) {
		this.rDay = rDay;
	}

	public String getAmpm() {
		return ampm;
	}

	public void setAmpm(String ampm) {
		this.ampm = ampm;
	}

	public boolean isPermanent() {
		return permanent;
	}

	public void setPermanent(boolean permanent) {
		this.permanent = permanent;
	}
	
}
